package com.meefo.meeting.common;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;

//处理properties
@Component
public class PropertiesUtil {
    private static Properties handWriteProp;
    private static String path = null;
    List<String> childIds = new ArrayList<>();
    public static Properties getHandWriteProp(String proName) {
        try {
            if (handWriteProp == null) {
                handWriteProp = new Properties();
                handWriteProp.load(PropertiesUtil.class.getClassLoader().getResourceAsStream(proName + ".properties"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return handWriteProp;
    }

    public static String getProjectDir() {
        if (path == null) {
            PropertiesUtil pu = new PropertiesUtil();
            return pu.getpd();
        } else {
            return path;
        }

    }

    public String getpd() {
        String projectDir = Thread.currentThread().getContextClassLoader().getResource(".").getPath()+"resources/";
        try {
            projectDir = URLDecoder.decode(projectDir, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        int linux = System.getProperty("os.name").toLowerCase().indexOf("linux");
        System.out.println("linux:"+linux);
        if (linux<0){
            projectDir=projectDir.substring(1);
        }
        return projectDir;
    }


}
